package com.bjsxt.controller.system;

import com.bjsxt.aspectj.annotation.Log;
import com.bjsxt.aspectj.enums.BusinessType;
import com.bjsxt.domain.CheckItem;
import com.bjsxt.dto.CheckItemDto;
import com.bjsxt.service.CheckItemService;
import com.bjsxt.utils.ShiroSecurityUtils;
import com.bjsxt.vo.AjaxResult;
import com.bjsxt.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 检查单控制层
 */
@RestController
@RequestMapping("system/checkItem")
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;


    /**
     * 分页查询检查单
     *
     * @param checkItemDto
     * @return
     */
    @GetMapping("listCheckItemForPage")
    public AjaxResult listCheckItemForPage(CheckItemDto checkItemDto) {
        DataGridView dataGridView = this.checkItemService.listCheckItemPage(checkItemDto);
        return AjaxResult.success("查询成功", dataGridView.getData(), dataGridView.getTotal());
    }

    /**
     * 添加检查单
     *
     * @param checkItemDto
     * @return
     */
    @PostMapping("addCheckItem")
    @Log(title = "添加检查单", businessType = BusinessType.INSERT)
    public AjaxResult addCheckItem(@Validated CheckItemDto checkItemDto) {
        checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(this.checkItemService.addCheckItem(checkItemDto));
    }

    /**
     * 修改检查单
     *
     * @param checkItemDto
     * @return
     */
    @PutMapping("updateCheckItem")
    @Log(title = "修改检查单", businessType = BusinessType.UPDATE)
    public AjaxResult updateCheckItem(@Validated CheckItemDto checkItemDto) {
        checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(this.checkItemService.updateCheckItem(checkItemDto));
    }

    /**
     * 根据checkItemId查询一条检查单
     *
     * @param checkItemId
     * @return
     */
    @GetMapping("getCheckItemById/{checkItemId}")
    public AjaxResult getCheckItemById(@PathVariable @Validated @NotNull(message = "checkItemId不能为空") Long checkItemId) {
        return AjaxResult.success(this.checkItemService.getOne(checkItemId));
    }

    /**
     * 根据checkItemIds删除检查单
     *
     * @param checkItemIds
     * @return
     */
    @DeleteMapping("deleteCheckItemByIds/{checkItemIds}")
    @Log(title = "删除检查单", businessType = BusinessType.DELETE)
    public AjaxResult deleteCheckItemByIds(@PathVariable @Validated @NotNull(message = "checkItemIds不能为空") Long[] checkItemIds) {
        return AjaxResult.toAjax(this.checkItemService.deleteCheckItemByIds(checkItemIds));
    }

    /**
     * 查询所有可用的检查单
     *
     * @return
     */
    @GetMapping("selectAllCheckItem")
    public AjaxResult selectAllCheckItem() {
        return AjaxResult.success(this.checkItemService.queryAllCheckItems());
    }

}
